package main

import (
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/cache"
	"github.com/gofiber/fiber/v2/middleware/cors"
	"github.com/gofiber/fiber/v2/middleware/logger"
	"github.com/gofiber/fiber/v2/middleware/recover"
	"github.com/gofiber/template/html"
	"log"
	"no-watermark/app/router"
	"os"
	"os/signal"
)

//https://v.douyin.com/YYuM1x5/
func main() {
	engine := html.New("./views", ".html")
	app := fiber.New(fiber.Config{
		Prefork:       true,   //开启fork进程
		Views:         engine, //使用模板引擎
		StrictRouting: true,   //严格的路由
	})

	app.Use(recover.New()) //错误恢复
	app.Use(logger.New())  //日志
	app.Use(cache.New())   //缓存
	app.Use(cors.New(cors.Config{
		AllowOrigins:     "*",
		AllowHeaders:     "*",
		AllowMethods:     "*",
		AllowCredentials: false,
	})) //跨域
	app.Static("/storage", "storage") //设置静态路径

	//所有的路由
	router.NewRouter(app)

	go func() {
		var addr = "0.0.0.0:8080"
		log.Fatal(app.Listen(addr))
	}()

	c := make(chan os.Signal, 1)
	//signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
	signal.Notify(c, os.Interrupt)
	_ = <-c
	log.Println("Gracefully shutting down...")
	_ = app.Shutdown()
}
